import VueRouter from "vue-router";
import Vue from "vue";

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/menu_product'
    },
    // {
    //   path: '*',
    //   redirect: '/demo'
    // }
  ]
});

// 采用扫描 modules 目录的方式加载路由
const ctx = require.context("./modules", true, /route.js$/);
ctx.keys().forEach((name) => {
  (ctx(name).default || ctx(name) || []).forEach((item) => {
    router.addRoute(item);
  });
});

export default router;
